# @Time:        2024/7/5 上午10:25
# @USER:        lihuizhuo
# @Site:        www.swust.edu.cn
# @File:        M
# @Software:    PyCharm
# @license:     Copyright(C), swust
# @Author:      huizhuo
# @Email:       huizhuoli@foxmail.com
# @Version:     V1.1.0
import pygame


class ActionByMulti:
    def __init__(self, file_path):
        self.image_list = []
        self.file_path = file_path
        self.image_index = 0
        for i in range(1, 10):
            image = pygame.image.load("resources/images/welcome/" + str(i) + "-1.png")
            print("resources/images/welcome/" + str(i) + "-1.png")
            self.image_list.append(image)

    def get_image(self):
        current_image = self.image_list[self.image_index]
        self.image_index += 1
        if self.image_index >= len(self.image_list):
            self.image_index = 0

        return current_image


class Actor:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.multi_image = ActionByMulti("resources/images/welcome/")

    def draw(self, screen):
        screen.blit(self.multi_image.get_image(), (self.x, self.y))

    def run(self):
        self.x += 5
        self.y += self.x * 3 + 1;
        if self.x > 1280:
            self.x = 20
        if self.y > 720:
            self.y = 20


def game_run():
    """
    游戏运行
    :return:
    """
    # pygame setup
    pygame.init()
    # set up the display 窗口
    screen = pygame.display.set_mode((1280, 720))
    clock = pygame.time.Clock()
    running = True  # 类型 变量名
    actor = Actor(20, 20)
    actor2 = Actor(200, 200)

    backgroud = pygame.image.load("resources/images/welcome/welcome.jpg")

    while running:
        # poll for events
        # pygame.QUIT event means the user clicked X to close your window
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        # fill the screen with a color to wipe away anything from last frame
        # screen.fill("purple")
        #
        screen.blit(backgroud, (0, 0))
        actor.draw(screen)
        actor2.draw(screen)

        # RENDER YOUR GAME HERE

        # flip() the display to put your work on screen
        pygame.display.flip()

        clock.tick(20)  # limits FPS to 60

        actor.run()
        actor2.run()

    pygame.quit()


if __name__ == '__main__':
    game_run()
